package com.xiaomi.test;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.daomain.Shoe;
import com.qf.mapper.ShoeMapper;
import com.xiaomi.entity.TbUser;
import com.xiaomi.entity.TbUserExample;
import com.xiaomi.mapper.TbUserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.InputStream;
import java.util.List;

/**
 * @author 10537
 * @version V1.0
 * @Date 2021/9/26 15:23
 */

public class Demo1 {
    @Test
    public void Test ()throws Exception{
        InputStream is = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(is);
        SqlSession sqlSession = build.openSession();
        TbUserMapper mapper = sqlSession.getMapper(TbUserMapper.class);

        List<TbUser> tbUsers = mapper.selectByExample(null);
        for (TbUser tbUser : tbUsers) {
            System.out.println(tbUser);
        }

        System.out.println("==============================================================");

        TbUserExample tbUserExample=new TbUserExample();
        TbUserExample.Criteria criteria=tbUserExample.createCriteria();
        //where and username=?
        criteria.andUsernameEqualTo("admin");
        List<TbUser> tbUsers1 = mapper.selectByExample(tbUserExample);
        for (TbUser tbUser : tbUsers1) {
            System.out.println(tbUser);
        }

        System.out.println("==============================================================");

        TbUser tbUser=new TbUser();
        tbUser.setId(3);
        tbUser.setEmail("1029000@qq.com");
        mapper.updateByPrimaryKeySelective(tbUser);

    }
}
